<?php
class Page{

    //传统的做法是判断是女性用户和男性用户，会用大量if else
/*    function index(){

        if(isset($_GET['female'])){

        }else{

        }
    }
    */

    protected $strategy;
    function index(){
        echo 'AD::';
        $this->strategy->showAd();
        echo '<br />';

        echo 'Category::';
        $this->strategy->showCategory();
    }
    function setStrategy(\vendor\UserStrategy $strategy){
        $this->strategy = $strategy;
    }
}

spl_autoload_register();
$page = new Page();

//如果加入第三种分类，只要新增一个UserStrategy()策略
if(isset($_GET['female'])){
    $strategy = new \vendor\FemalUserStrategy();
}else{
    $strategy = new \vendor\MailUserStrategy();
}
$page->setStrategy($strategy);
$page->index();